package com.sgb.trip.view.activity;

import android.content.res.ColorStateList;
import android.view.View;

import androidx.fragment.app.Fragment;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.google.android.material.tabs.TabLayout;
import com.sgb.link.router.PathTrip;
import com.sgb.link.view.widget.CustomXTabLayout;
import com.sgb.trip.R;
import com.sgb.trip.databinding.TripActivityFlightOrdersBinding;
import com.sgb.trip.view.fragment.FlightOrdersSelfFragment;
import com.swgk.core.common.base.BaseActivity;
import com.swgk.core.common.base.BaseViewModel;
import com.swgk.core.recyclerview.adapter.SlidingFragmentPagerAdapter;

import java.util.ArrayList;

/**
 * Time:2021/10/9
 * Author:黄淋
 * Description:用户中心机票订单
 */
@Route(path = PathTrip.FlightOrdersSelfActivity)
public class FlightOrdersSelfActivity extends BaseActivity<BaseViewModel, TripActivityFlightOrdersBinding> {

    private ArrayList<Fragment> mFragments;
    private String[] titles = {"全部", "待支付", "已关闭"};

    @Override
    protected int layoutId() {
        return R.layout.trip_activity_flight_orders;
    }

    @Override
    protected void createViewModel() {

    }

    @Override
    protected void init() {
        mBinding.actionBar.setOnBackClickListener(this);

        initTabLayout();
    }

    private void initTabLayout() {
        mFragments = new ArrayList<>();
        mFragments.add(FlightOrdersSelfFragment.newInstance(0));
        mFragments.add(FlightOrdersSelfFragment.newInstance(1));
        mFragments.add(FlightOrdersSelfFragment.newInstance(2));
        SlidingFragmentPagerAdapter pagerAdapter = new SlidingFragmentPagerAdapter(getSupportFragmentManager(), mFragments, titles);
        mBinding.vpMyFlightOrder.setAdapter(pagerAdapter);
        mBinding.vpMyFlightOrder.setOffscreenPageLimit(1);
        //取消tab点击效果
        mBinding.tabLayoutFlightOrder.setTabRippleColor(ColorStateList.valueOf(getResources().getColor(R.color.transparent)));
        mBinding.tabLayoutFlightOrder.setupWithViewPager(mBinding.vpMyFlightOrder);
        mBinding.tabLayoutFlightOrder.setNormalColor96();
        mBinding.tabLayoutFlightOrder.addOnTabSelectedListener(new CustomXTabLayout.SimpleSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                int tabPosition = tab.getPosition();
                mBinding.vpMyFlightOrder.setCurrentItem(tabPosition);

            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.iv_back_red) {//返回
            finish();
        }
    }
}
